/***************************************************************************
*   Copyright (C) 2011 by Chuck Gao & Alex Liu                             *
*                                                                          *
*   This program is free software: you can redistribute it and/or modify   *
*   it under the terms of the GNU General Public License as published by   *
*   the Free Software Foundation, either version 3 of the License, or      *
*   (at your option) any later version.                                    *
*                                                                          *
*   This program is distributed in the hope that it will be useful,        *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
*   GNU General Public License for more details.                           *
*                                                                          *
*   You should have received a copy of the GNU General Public License      *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
*                                                                          *
*   Contact author: chuckgao.cg@gmail.com                                  *
*                   alex2202375@gmail.com                                  *
***************************************************************************/

import Qt 4.7


QtObject {
    property Component headerRenderer:
        Component {
        id: defaultHeaderRenderer

        Text {
            width: cellWidth
            height: cellHeight
            anchors.centerIn: parent
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            font.bold: true
            font.pointSize: width ? width / 4 : 1
            text: model.modelData
            color: "white"
        }
    }

    property Component daysRenderer:
        Component {
        Item {
            width: cellWidth
            height: cellHeight

            Rectangle {
                width: parent.width - 4
                height: parent.height - 4
                anchors.centerIn: parent
                radius: 4
                visible: dayText.text != ""
                color: model ? (model.current ? "lightgreen" : "white") : "lightgreen"
            }

            Text {
                id: dayText
                anchors.top: parent.top
                anchors.topMargin: 4
                anchors.right: parent.right
                anchors.rightMargin: 4

                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

                text: model ? model.day : ""
                color: model ? (model.current ? "red" : "black") : "red"
                font.pointSize: 16
            }

            Grid {
                columns: 3
                spacing: 2
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 10
                visible: (dayText.text != "") && ( model ? (model.day % 2 == 0) : 0 )

                Rectangle { color: "red"; width: 10; height: 4 }
                Rectangle { color: "green"; width: 10; height: 4 }
                Rectangle { color: "lightblue"; width: 10; height: 4 }
                Rectangle { color: "cyan"; width: 10; height: 4 }
                Rectangle { color: "magenta"; width: 10; height: 4 }
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    // Go to the "Day of plan" detailed view
                    console.debug("Day selected")
                    myCalendar.showDayView()
                }
            }
        }
    }
}
